/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf.beans.admin;

import java.sql.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import manager.AdvertisementManager;
import model.admin.Advertisement;

/**
 *
 * @author Danh
 */
@ManagedBean
@SessionScoped
public class AdvertisementsBean {

    private int adverId;
    private int imageId;
    private String exprired_Date;
    private Date create_Date;
    private String company_Issued;
    private boolean adverStatus;

    public int getAdverId() {
        return adverId;
    }

    public void setAdverId(int adverId) {
        this.adverId = adverId;
    }

    public int getImageId() {
        return imageId;
    }

    public void setImageId(int imageId) {
        this.imageId = imageId;
    }

    public String getExprired_Date() {
        return exprired_Date;
    }

    public void setExprired_Date(String exprired_Date) {
        this.exprired_Date = exprired_Date;
    }

    public Date getCreate_Date() {
        return create_Date;
    }

    public void setCreate_Date(Date create_Date) {
        this.create_Date = create_Date;
    }

    public String getCompany_Issued() {
        return company_Issued;
    }

    public void setCompany_Issued(String company_Issued) {
        this.company_Issued = company_Issued;
    }

    public boolean isAdverStatus() {
        return adverStatus;
    }

    public void setAdverStatus(boolean adverStatus) {
        this.adverStatus = adverStatus;
    }

    public AdvertisementsBean() {
    }

    public AdvertisementsBean(int adverId, int imageId, String exprired_Date, Date create_Date, String company_Issued, boolean adverStatus) {
        this.adverId = adverId;
        this.imageId = imageId;
        this.exprired_Date = exprired_Date;
        this.create_Date = create_Date;
        this.company_Issued = company_Issued;
        this.adverStatus = adverStatus;
    }

    public List<Advertisement> loadData() {
        AdvertisementManager m = new AdvertisementManager();
        return m.getAdvertisement();
    }

    public void deleteAdver(int id) {
        AdvertisementManager mana = new AdvertisementManager();
        boolean result = mana.delete(id);
        if (result) {
            loadData();
        }
    }

    public void reset() {
        java.util.Date date = new java.util.Date();
        this.imageId = 0;
        this.create_Date = new Date(date.getTime());
        this.adverStatus = false;
        this.company_Issued = "";
        this.exprired_Date = "";
    }
}
